﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MdflCommonUtilsNet4 {
    public class MathUtil {
        /// <summary>
        /// 将小时数换算为为 天 时 分. 如入参hours为 25.2, 则返回 1天 1时 12分
        /// </summary>
        /// <param name="hours">小时数</param>
        /// <returns>tuple.item1 天; tuple.item2 时; tuple.item3 分</returns>
        public static Tuple<int, int, int> GetDayHourMinuteFromHour(decimal hours) {
            decimal dayDivisor = 24;
            decimal minuteDivisor = 60;

            decimal calcedDays = Math.Floor(hours / dayDivisor);

            decimal calcedHours = hours % dayDivisor;

            decimal calcedHoursIntegerPart = Math.Floor(calcedHours);
            decimal calcedHoursFractionalPart = calcedHours - calcedHoursIntegerPart;
            decimal minutes = Math.Ceiling(calcedHoursFractionalPart * minuteDivisor);

            return new Tuple<int, int, int>((int)calcedDays, (int)calcedHours, (int)minutes);
        }
    }
}
